package mvc.command.character
{
	import com.adobe.cairngorm.commands.ICommand;
	import com.adobe.cairngorm.control.CairngormEvent;
	import com.adobe.cairngorm.control.CairngormEventDispatcher;
	
	import iris.managers.IrisPopUpManager;
	
	import mvc.control.CharacterEvent;
	
	import mx.core.IFlexDisplayObject;
	
	import nz.co.codec.flexorm.EntityManager;
	
	import view.design.DesignCharacter;

	public class RemoveCharacterYesCmd extends CharacterCmd implements ICommand
	{
		public function execute(event:CairngormEvent):void
		{
			var dsnCharacter:DesignCharacter = event.data.dsnCharacter as DesignCharacter;

			EntityManager.instance.remove(dsnCharacter.tblCharacterVO);

			super._dsnCharacters.tabCharacters.selectedIndex
				= Math.max(0, super._dsnCharacters.tabCharacters.getChildIndex(dsnCharacter) - 1);
			super._dsnCharacters.tabCharacters.removeChild(dsnCharacter);

			var mvcEvent:CharacterEvent = new CharacterEvent(CharacterEvent.CHARACTERS_REFRESHED);
			CairngormEventDispatcher.getInstance().dispatchEvent(mvcEvent);

			IrisPopUpManager.removePopUp(event.data.popUp as IFlexDisplayObject, IrisPopUpManager.EFFECT_BLUR);
		}
	}
}